package com.ioog.domain.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name="category")
public class Category implements Serializable {
	
	private static final long serialVersionUID = -109746309700821576L;

	@Id@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="category_id")
	private Long id;
	
	@Column(name="category_name", length=25,  unique=true, nullable=false)
	@org.hibernate.annotations.Index(name="idx_category_name")
	private String name;
	
	@Column(name="category_desc", length=255)
	private String description;
	
	@Temporal(TemporalType.TIMESTAMP)
    @Column(name="created", nullable = false, updatable = false)
    private Date created = new Date();
	
	public Category() { }

	public Category(String name, String description) {
		super();
		this.name = name;
		this.description = description;
	}

	public Long getId() { return id; }

	public String getName() { return name; }
	public void setName(String name) { this.name = name; }

	public String getDescription() { return description; }
	public void setDescription(String description) { this.description = description; }
	
	public Date getCreated() { return created; }

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((created == null) ? 0 : created.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Category other = (Category) obj;
		if (created == null) {
			if (other.created != null)
				return false;
		} else if (!created.equals(other.created))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}	
}
